<?php

/**
 * @Author: Eden
 * @Date:   2019-07-10 16:28:02
 * @Last Modified by:   Eden
 * @Last Modified time: 2019-07-10 16:48:31
 */
namespace App\Transformers;

use App\Models\Message;
use League\Fractal\TransformerAbstract;

class MessageTransformer extends TransformerAbstract
{

	protected $availableIncludes = ['project'];

	public function transform(Message $message)
	{
		return [
			'id' => $message->id,
			'project_id' => $message->project_id,
			'line' => $message->line,
			'line_set' => $message->line_set,
			'offline' => $message->offline,
			'online' => $message->online,
			'lost_package' => $message->lost_package,
			'change' => $message->change,
			'check_date' => $message->check_date,
			'created_at' => $message->created_at->toDateTimeString(),
			'updated_at' => $message->updated_at->toDateTimeString(),
		];
	}

	public function includeProject(Message $message)
	{
		if ($message->project)
		{
			return $this->item($message->project, new ProjectTransformer());
		}
	}

}
